/*
 * @lc app=leetcode.cn id=912 lang=javascript
 *
 * [912] 排序数组
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @return {number[]}
 */
var sortArray = function (nums) {
  let unsortedIndex = nums.length - 1;
  let unsorted = true;

  while (unsorted) {
    // 如果未被置为true，则说明已经排序完成
    unsorted = false;

    for (let i = 0; i < unsortedIndex; i++) {
      if (nums[i] > nums[i + 1]) {
        let temp = nums[i];
        nums[i] = nums[i + 1];
        nums[i + 1] = temp;

        unsorted = true;
      }
    }
  }

  return nums;
};
// @lc code=end

// @after-stub-for-debug-begin
module.exports = sortArray;
// @after-stub-for-debug-end
